# views.py
# 导入响应类
from django.http import HttpResponse
# 用来处理客户端对hello的请求
def hello_view(request):
    html = '<h1>Hello World</h1>'
    # 创建一个响应对象
    return HttpResponse(html)
def index_view(request):
    html = '<h2>这是我的首页</h2>'
    return HttpResponse(html)
def page1_view(request):
    html = '这是编号为1的网站'
    return HttpResponse(html)
def page2_view(request):
    return HttpResponse('这是编号为2的网站')
# 如果在路由地址中使用了转换器，需要将转换器放入到参数中
def pagen_view(request, pno):
    html = f'<h3>这是第<span style="color: red;">{pno}</span>个网站</h3>'
    return HttpResponse(html)
def login_view(request, username, password):
    html = f'''
        <h1>登录成功！</h1>
        <p>用户名：{username}</p>
        <p>密码：{password}</p>
    '''
    return HttpResponse(html)
def calc_view(request, num1, op, num2):
    # 如果运算符op不是加减乘除
    if op not in ['add', 'sub', 'mul', 'div']:
        return HttpResponse('错误的运算符')
    elif op == 'add':
        result = num1 + num2
    elif op == 'sub':
        result = num1 - num2
    elif op == 'mul':
        result = num1 * num2
    else:
        result = num1 / num2
    return HttpResponse(result)
def phone_view(request, tel):
    return HttpResponse(f'手机号码：{tel}')
def birthday_view(request, year, month, date):
    return HttpResponse(f'生日为{year}年{month}月{date}日')
def email_view(request, email, num):
    return HttpResponse(f'欢迎回来！邮箱：{email}')